package com.czk.springcloud.config;

import com.czk.springcloud.entity.Payment;
import com.czk.springcloud.model.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/11/19 18:34
 */
@Configuration
@ControllerAdvice
@Slf4j
public class GlobalExceptionConfig {
    @ExceptionHandler(BizException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Payment exception(BizException e) {
        log.error("业务异常 ex={}", e.getMessage(), e);
        Payment payment = new Payment();
        payment.setSerial("失败");
        return payment;
    }
}
